angular.module("UranusWei", ['ui.router', 'ngTouch', 'LocalStorageModule', 'ngAnimate', 'vgSrc', 'pasvaz.bindonce', 'UranusIScroll', 'UranusPlus', 'AppConfig'])
    .config(['$stateProvider', '$locationProvider', '$urlRouterProvider', function ($stateProvider, $locationProvider, $urlRouterProvider) {
        //忽略大小写
        $urlRouterProvider.rule(function ($injector, $location) {
            var path = $location.path(), normalized = path.toLowerCase();

            if (path != normalized) {
                return normalized + location.search.toLowerCase();
            }
        });
        var version = window.version;
        $stateProvider
            .state('main', {   //模板页
                url: '/main',
                templateUrl: 'html/main.html?v=' + version,
                controller: "main"
            }).state("main.home", {  //精选页
                url: '/home',
                templateUrl: '/html/home/home.html?v=' + version,
                controller: 'mainhome'
            }).state("hotactives", {  //热门活动
                url: '/home/hotactives',
                templateUrl: '/html/home/hotactives.html?v=' + version,
                controller: 'hotactives'
            }).state("/weixin", { //关注微信流程
                url: '/weixin',
                templateUrl: '/html/home/weixin.html?v=' + version,
                controller: 'weixin'
            }).state("main.day", { //天天赚
                url: '/day',
                templateUrl: '/html/day/currentlist.html?v=' + version,
                controller: 'currentlist'
            }).state("main.list", { //列表页
                url: '/list',
                templateUrl: '/html/month/list.html?v=' + version,
                controller: 'mainlist'
            }).state("main.mine", { //个人中心页
                url: '/mine',
                templateUrl: '/html/mine/index.html?v=' + version,
                controller: 'mainmine'
            }).state("productindex", {  //单品页
                url: '/product/{productcode:(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{0,100}}',
                templateUrl: '/html/month/index.html?v=' + version,
                controller: 'productindex'
            }).state("anxin", {  //安心签合同
                url: '/contract/anxin',
                templateUrl: '/html/contract/anxin.html?v=' + version,
                controller: 'currentcp'
            }).state("cfca", {  //CFCA数字证书服务协议
                url: '/contract/cfca',
                templateUrl: '/html/contract/cfca.html?v=' + version,
                controller: 'currentcp'
            }).state("contract", {  //出借人合同
                url: '/product/contract',
                templateUrl: '/html/contract/contract.html?v=' + version,
                controller: 'productcp'
            }).state("oldcontract", {  //旧定期合同
                url: '/product/oldcontract',
                templateUrl: '/html/contract/oldcontract.html?v=' + version,
                controller: 'productcp'
            }).state("contractj", {  //借款人合同
                url: '/product/contractj',
                templateUrl: '/html/contract/contractj.html?v=' + version,
                controller: 'productcp'
            }).state("contract-msg", {  //风险提示函
                url: '/contract/contract-msg',
                templateUrl: '/html/contract/contractj-msg.html?v=' + version,
                controller: 'currentcp'
            }).state("contract-xy", {  //有利金服免责声明
                url: '/contract/contract-xy',
                templateUrl: '/html/contract/contractj-xy.html?v=' + version,
                controller: 'currentcp'
            }).state("contract-serves", { //定向委托投资协议定期
                url: '/contract/contract-serves',
                templateUrl: '/html/contract/contract-serves.html?v=' + version,
                controller: 'currentcp'
            }).state("contract-hqserves", {  //定向委托投资协议活期
                url: '/contract/contract-hqserves',
                templateUrl: '/html/contract/contract-hqserves.html?v=' + version,
                controller: 'currentcp'
            }).state("servicedeal", {//用户协议
                url: '/register/servicedeal',
                templateUrl: '/html/safety/servicedeal.html?v=' + version,
                controller: 'servicedeal'
            }).state("login", {  //登录
                url: '/login/index',
                templateUrl: '/html/safety/login.html?v=' + version,
                controller: 'login'
            }).state("register", {  //注册
                url: '/register/index',
                templateUrl: '/html/safety/register.html?v=' + version,
                controller: 'register'
            }).state("modifypassword", {  //修改密码
                url: '/safety/modifypassword',
                templateUrl: '/html/safety/modifypassword.html?v=' + version,
                controller: 'modifypassword'
            }).state("findpassword", {  //找回密码
                url: '/register/findpassword',
                templateUrl: '/html/safety/findpassword.html?v=' + version,
                controller: 'findpassword'
            }).state("registersuccess", {  //注册成功页
                url: '/register/registersuccess',
                templateUrl: '/html/safety/registersuccess.html?v=' + version,
                controller: 'registersuccess'
            }).state("dqinvestrecords", { //月月赚明细
                url: '/mine/dqinvestrecords',
                templateUrl: '/html/mine/dqinvestrecords.html?v=' + version,
                controller: 'dqinvestrecords'
            }).state("dqinvestrecords.waitmoney", { //月月赚明细持有中
                url: '/waitmoney',
                templateUrl: '/html/mine/dqinvestrecordslist.html?v=' + version,
                controller: 'waitmoney'
            }).state("dqinvestrecords.havemoney", { //月月赚明细已回款
                url: '/havemoney',
                templateUrl: '/html/mine/dqinvestrecordslist.html?v=' + version,
                controller: 'havemoney'
            }).state("dqinvestdetail", { //月月赚明细详情
                url: '/mine/dqinvestdetail/{id}',
                templateUrl: '/html/mine/dqinvestdetail.html?v=' + version,
                controller: 'dqinvestdetail'
            }).state("transactionrecords", { //交易记录(个人中心进入)
                url: '/mine/transactionrecords',
                templateUrl: '/html/mine/transactionrecords.html?v=' + version,
                controller: 'transactionrecords'
            }).state("more", { //其他更多页
                url: '/mine/more',
                templateUrl: '/html/mine/more.html?v=' + version,
                controller: 'mainmore'
            }).state("setting", {  //设置
                url: '/mine/setting',
                templateUrl: '/html/mine/setting.html',
                controller: 'setting'
            }).state("assessment", {  //设置
                url: '/mine/assessment',
                templateUrl: '/html/mine/assessment.html',
                controller: 'setting'
            }).state("bindcard", {  //绑卡
                url: '/setting/bindcard',
                templateUrl: '/html/mine/bindcard.html',
                controller: 'gobindcard'
            }).state("realname", {  //实名认证
                url: '/mine/realname',
                templateUrl: '/html/mine/realname.html?v=' + version,
                controller: 'realname'
            }).state("orderconfirmpayment", {  //订单确认页
                url: '/month/orderconfirmpayment/{id}',
                templateUrl: '/html/month/orderconfirmpayment.html?v=' + version,
                controller: 'orderconfirmpayment'
            }).state("transfercomplete", {  //交易完成页
                url: '/other/transfercomplete',
                templateUrl: '/html/other/transfercomplete.html?v=' + version,
                controller: 'transfercomplete'
            }).state("recharge", {  //充值页面
                url: '/mine/recharge',
                templateUrl: '/html/mine/recharge.html?v=' + version,
                controller: 'recharge'
            }).state("withdrawals", {  //提现页面
                url: '/mine/withdrawals',
                templateUrl: '/html/mine/withdrawals.html?v=' + version,
                controller: 'withdrawals'
            }).state("fmwithdrawals", {  //富民提现页面
                url: '/mine/fmwithdrawals',
                templateUrl: '/html/mine/fmwithdrawals.html?v=' + version,
                controller: 'fmwithdrawals'
            }).state("waitting", {  //充值等待页面
                url: '/other/waitting',
                templateUrl: '/html/other/waitting.html?v=' + version,
                controller: 'waitting'
            }).state("transferconfirm", {  //交易完成页面
                url: '/other/transferconfirm',
                templateUrl: '/html/other/transferconfirm.html?v=' + version,
                controller: 'transferconfirm'
            }).state("youliweal", {  //有利福利
                url: '/mine/youliweal',
                templateUrl: '/html/mine/youliweal.html?v=' + version,
                controller: 'youliweal'
            }).state("youliweal.ratecoupon", {  //加息券
                url: '/ratecoupon',
                templateUrl: '/html/mine/ratecoupon.html?v=' + version,
                controller: 'youliwealratecoupon'
            }).state("youliweal.redpacket", {  //红包
                url: '/redpacket',
                templateUrl: '/html/mine/redpacket.html?v=' + version,
                controller: 'youliwealredpacket'
            }).state("youliweal.experience", {  //体验金
                url: '/experience',
                templateUrl: '/html/mine/experience.html?v=' + version,
                controller: 'youliwealexperience'
            }).state("wxshare", {  //微信分享
                url: '/mine/wxshare',
                templateUrl: '/html/mine/wxshare.html?v=' + version,
                controller: 'wxinvitebonus'
            }).state("invitebonus", {  //邀请奖金
                url: '/mine/invitebonus',
                templateUrl: '/html/mine/invitebonus.html?v=' + version,
                controller: 'invitebonus'
            }).state("oldbonus", {  //老版本邀请好友拿奖金
                url: '/mine/oldbonus',
                templateUrl: '/html/mine/oldbonus.html?v=' + version,
                controller: 'inviterules'
            }).state("inviterules", {  //邀请好友详细规则
                url: '/mine/inviterules',
                templateUrl: '/html/mine/inviterules.html?v=' + version,
                controller: 'inviterules'
            }).state("invitebonus.bonusdetail", {  //奖金明细
                url: '/bonusdetail',
                templateUrl: '/html/mine/bonusdetail.html?v=' + version,
                controller: 'bonusdetail'
            }).state("invitebonus.friendlist", {  //好友列表
                url: '/friendlist',
                templateUrl: '/html/mine/friendlist.html?v=' + version,
                controller: 'friendlist'
            }).state("totalpricedetail", {  //资产总额详情
                url: '/mine/totalpricedetail',
                templateUrl: '/html/mine/totalpricedetail.html?v=' + version,
                controller: 'totalpricedetail'
            }).state("totalearnings", {  //累计收益总额详情
                url: '/mine/totalearnings',
                templateUrl: '/html/mine/totalearnings.html?v=' + version,
                controller: 'totalearnings'
            }).state("problem", {  //常见问题列表
                url: '/more/problem',
                templateUrl: '/html/mine/problem.html?v=' + version,
                controller: 'problem'
            }).state("problemdetail", {  //常见问题详情
                url: '/more/problemdetail',
                templateUrl: '/html/mine/problemdetail.html?v=' + version,
                controller: 'problemdetail'
            }).state("nofind", {  //404
                url: '/404',
                templateUrl: '/html/other/404.html?v=' + version,
                controller: 'nofind'
            }).state("report", {//媒体报道
                url: '/more/report',
                templateUrl: '/html/mine/report.html?v=' + version,
                controller: 'report'
            }).state("reportdetails", {//媒体报道
                url: '/more/report/{time:[\\d]{8}|[\\d]{8}[_]{1}[a-z]{2}}',
                templateUrl: '/html/mine/reportdetails.html?v=' + version,
                controller: 'reportdetails'
            }).state("aboutus", {//关于我们
                url: '/more/aboutus',
                templateUrl: '/html/mine/aboutus.html?v=' + version,
                controller: 'aboutus'
            }).state("currentdetail", {  //天天赚详情页
                url: '/day/currentdetail',
                templateUrl: '/html/day/currentdetail.html?v=' + version,
                controller: 'currentlist'
            }).state("currentorderconfirmpayment", {  //天天赚订单确认
                url: '/day/currentorderconfirmpayment/{id}',
                templateUrl: '/html/day/currentorderconfirmpayment.html?v=' + version,
                controller: 'currentorderconfirmpayment'
            }).state("daydetailed", {  //天天赚账户
                url: '/mine/daydetailed',
                templateUrl: '/html/mine/daydetailed.html?v=' + version,
                controller: 'daydetailed'
            }).state("daywithdrawal", {  //天天赚账户
                url: '/mine/daywithdrawal',
                templateUrl: '/html/mine/daywithdrawal.html?v=' + version,
                controller: 'daywithdrawal'
            }).state("daygetdetailed", {  //天天赚明细
                url: '/mine/daygetdetailed',
                templateUrl: '/html/mine/daygetdetailed.html?v=' + version,
                controller: 'daygetdetailed'
            }).state("messagelist", {  //系统消息列表
                url: '/mine/messagelist',
                templateUrl: '/html/mine/messagelist.html?v=' + version,
                controller: 'messagelist'
            }).state("messagedetail", {  //系统消息明细
                url: '/mine/messagedetail',
                templateUrl: '/html/mine/messagedetail.html?v=' + version,
                controller: 'messagedetail'
            }).state("team", {  //团队介绍
                url: '/mine/team',
                templateUrl: '/html/mine/team.html?v=' + version,
                controller: 'team'
            }).state("about", {//关于我们
                url: '/more/about',
                templateUrl: '/html/mine/about.html?v=' + version,
                controller: 'about'
            }).state("hdhtml0719", { //关于我们
                url: "/hdhtml/hd20170719",
                templateUrl: "html/hdhtml/hd20170719.html?v=" + version,
                controller: 'about'
            }).state("hdhtml", { //banner页大型国企入股
                url: "/hdhtml/hd20170328",
                templateUrl: "html/hdhtml/hd20170328.html?v=" + version,
                controller: 'hdhtml'
            }).state("hdhtml0519", { //banner页大型国企入股5-19
                url: "/hdhtml/hd20170519",
                templateUrl: "html/hdhtml/hd20170519.html?v=" + version,
                controller: 'hdhtml0519'
            }).state("hdhtml0717", { //banner页大型国企入股7-17
                url: "/hdhtml/hd20170717",
                templateUrl: "html/hdhtml/hd20170717.html?v=" + version,
                controller: 'hdhtml0519'
            }).state("fmbank", { //富民银行
                url: "/hdhtml/fmbank",
                templateUrl: "html/hdhtml/fmbank.html?v=" + version,
                controller: 'fmbank'
            }).state("fmbankcg", { //富民银行
                url: "/hdhtml/fmbankcg",
                templateUrl: "html/hdhtml/fmbankcg.html?v=" + version,
                controller: 'fmbank'
            }).state("sjsafe", { //国家级安全三级
                url: "/hdhtml/sjsafe",
                templateUrl: "html/hdhtml/sjsafe.html?v=" + version,
                controller: 'fmbank'
            }).state("gansafe", { //公安网备案
                url: "/hdhtml/gansafe",
                templateUrl: "html/hdhtml/gansafe.html?v=" + version,
                controller: 'fmbank'
            }).state("hdyhtml", {//banner页
                url: "/hdhtml/hd20170329",
                templateUrl: "html/hdhtml/hd20170329.html?v=" + version,
                controller: 'hdyhtml'
            }).state("cctv", {//cctv页
                url: "/hdhtml/hd20170727",
                templateUrl: "html/hdhtml/hd20170727cctv.html?v=" + version,
                controller: 'hdyhtml'
            }).state("safe", {
                url: "/safety/safe",
                templateUrl: "html/safety/safe.html?v=" + version,
                controller: 'safe'
            }).state("safety", {  //首页安全保障
                url: '/home/safety',
                templateUrl: '/html/home/safety.html?v=' + version,
                controller: 'safety'
            })
            .state("newactivity", {  //新手专享
                url: '/home/newactivity',
                templateUrl: '/html/home/newactivity.html?v=' + version,
                controller: 'newactivity'
            })
            .state("20170630", {//初夏活动  活动页面格式！！！！/hdhtml/hd！！！！
                url: "/hdhtml/hd{id:[\\w]+}",
                templateUrl: function ($routeParams) {
                    return "html/hdhtml/hd" + $routeParams.id + ".html?v=" + version
                },
                controller: '20170404'
            }).state("endbanner", {//更多页banner
                url: "/hdhtml/end20170811",
                templateUrl: "html/hdhtml/end20170811.html?v=" + version,
                controller: 'hd20170410'
            }).state("endbanne", {//充值流程
                url: "/hdhtml/end20170901",
                templateUrl: "html/hdhtml/end20170901.html?v=" + version,
                controller: 'hd20170410'
            }).state("rechargecmb", {  //充值页面招商
                url: '/product/rechargecmb',
                templateUrl: '/html/month/rechargeCmb.html?v=' + version,
                controller: 'recharge'
            }).state("fmoutbank", {  //活期提现到银行卡
                url: '/safe/fmoutbank',
                templateUrl: '/html/safety/fmoutbank.html?v=' + version,
                controller: 'fmoutbank'
            }).state("weibankcardbtn", {  ///微信提现流程页面
                url: '/mine/weibankcardbtn',
                templateUrl: '/html/mine/weibankcardbtn.html?v=' + version,
                controller: 'bankcardbtn'
            }).state("weipurchaseflow", {  ///wei购买流程页面
                url: '/mine/weipurchaseflow',
                templateUrl: '/html/mine/weipurchaseflow.html?v=' + version,
                controller: 'purchaseflow'
            }).state("tjwh", {  //停机维护
                url: '/banner/tjwh',
                templateUrl: '/html/hdhtml/weihu/tjwh.html?v=' + version,
                controller: 'hd20170410'
            }).state("gqfj", {  //停机维护
                url: '/gqfj',
                templateUrl: '/html/hdhtml/weihu/gqfj.html?v=' + version,
                controller: 'hd20170410'
            }).state("infodis", {//信息披露
                url: "/hdhtml/infodis",
                templateUrl: "html/hdhtml/pmessage/index.html?v=" + version,
                controller: 'infodis'
            })
        $urlRouterProvider.when("/product/orderconfirmpayment?id", "/product/orderconfirmpayment/{id}");
        $urlRouterProvider.when("/", "/main/home");//设置根目录的匹配
        $urlRouterProvider.otherwise('/404');//未匹配到的时候跳转的控制器
        $locationProvider.html5Mode(true);//开启h5地址
    }]).run(['$http', 'CacheFactory', function ($http, CacheFactory) {
        /*------------------推广来源----------------------*/
        /*从url里面截取参数*/
        function getQueryString(name) { 
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        var typeId = getQueryString("sourcetypeid");
        if (!typeId) {
            typeId = CacheFactory.getSourceTypeId()
        }
        //如果存在就放到缓存里面，覆盖已有的
        if (typeId != "" && typeId != undefined && typeId != null) {
            $http({
                url: "https://api.youlijinfu.com/api/source/GetSourceTypeIdByName?name=" + typeId,
                // url: "http://192.168.0.109:9005/api/source/GetSourceTypeIdByName?name=" + typeId,
                method: "GET",
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                data: { name: typeId },
                timeout: 60 * 1000
            }).success(function (result) {
                localStorage.setItem("sourcetypeid", result);
            }).error(function () {
                if (typeof err == "function") {
                    err({ code: -1, data: '请求失败，请稍后再试' });
                }
            });
        }
        /*------------------推广来源----------------------*/
    }]);
